<div class="layui-card layadmin-header">
  <div class="layui-breadcrumb" lay-filter="breadcrumb">
    <a><cite>活动管理</cite></a>
    <a><cite>空投列表</cite></a>
  </div>
</div>

<div class="layui-fluid">
  <div class="layui-card">
    <div class="layadmin-search">
      <form class="layui-form" lay-filter="form_order_search">
        <script type="text/html" template lay-done="layui.data.done()">
          <div class="layui-inline">
            <div class="layui-form-label">关键字搜索</div>
            <div class="layui-input-inline" style="width: 250px">
              <input type="text" name="keyword" value="{{decodeURIComponent(layui.router().search.keyword || '')}}"
                     class="layui-input" placeholder="请输入用户昵称，手机号或商品名称">
            </div>
          </div>
          <div class="layui-inline">
            <div class="layui-form-label">空投状态</div>
            <div class="layui-input-inline" style="width: 100px">
              <select name="status">
                <option value="">全部</option>
                <option value="3">空投中</option>
                <option value="1">成功</option>
                <option value="2">失败</option>
              </select>
            </div>
          </div>
          <div class="layui-inline layui-btn-group">
            <button type="submit" lay-submit class="layui-btn" lay-filter="submit_order_search">
              <i class="layui-icon layui-icon-search"></i>查询
            </button>
            <button type="submit" lay-submit class="layui-btn layui-btn-warm"
                    lay-filter="reset_order_search">
              <i class="layui-icon layui-icon-close"></i>重置
            </button>
          </div>
        </script>
      </form>
    </div>
    <div class="layui-card-body">
      <div id="table_order"></div>
      <script type="text/html" id="tpl_buyer">
        {{d.user.mobile}}
      </script>
      <script type="text/html" id="tpl_status">
        {{# if (d.status === 1) { }}
        <span class="layui-font-green">成功</span>
        {{# } }}
        {{# if (d.status === 2) { }}
        <span class="layui-font-red" lay-tips="{{d.error_msg}}">失败</span>
        {{# } }}

        {{# if (d.status === 0) { }}
        <span class="layui-font-blue">空投中</span>
        {{# } }}
      </script>
      <script type="text/html" id="tpl_agent">
        {{d.agent ? d.agent.name : ''}}
      </script>
      <script type="text/html" id="tpl_tool">
        {{# if (d.status === 2 ) { }}
        <div class="ant-divider"></div>
        <a class="layui-table-link layui-font-green" lay-event="reissue">
          补发
        </a>
        {{# } }}
      </script>
    </div>
  </div>
</div>

<script>
  layui.data.done = function () {
    layui.use(['fox_table'], function () {
      let $ = layui.$
        , fox_table = layui.fox_table
        , admin = layui.admin
        , form = layui.form
      form.render()

      let resourceUrl = 'admin/airdrops'

      // 列表查询
      fox_table.render({
        id: 'table_order'
        , url: resourceUrl
        , cols: [[
          {title: 'ID', field: 'id', width: 80, align: "center", sort: true}
          , {title: '所属代理', templet: '#tpl_agent', width: 150}
          , {title: '商品ID', field: 'goods_id', width: 80, align: "center"}
          , {title: '产品名称', field: 'goods_name', width: 150}
          , {title: '数量', field: 'number', width: 80, align: "center"}
          , {title: '接收人', field: 'nickname', minWidth: 100}
          , {title: '手机号', field: 'mobile', width: 150, align: "center"}
          , {title: '订单状态', templet: '#tpl_status', width: 100, align: "center"}
          , {title: '下单时间', field: 'created_at', width: 180, align: "center"}
          // , {title: '操作', width: 100, align: 'left', fixed: 'right', toolbar: '#tpl_tool'}
        ]]
      });


      //监听操作栏
      fox_table.toolbar(function (obj) {
        let data = obj.data;
        if (obj.event === 'reissue') {
          layer.confirm('确定补发该藏品么?', function (index) {
            admin.post(resourceUrl + '/' + data.id + '/reissue', {}, function (res) {
              layer.close(index);
              fox_table.reload(); //重载表格
            })
          });
        }
      });

      //搜索
      form.on('submit(submit_order_search)', function (d) {
        fox_table.reload(d.field);
        return false;
      });
      //重置
      form.on('submit(reset_order_search)', function (d) {
        $("input[name='keyword']").val('');
        $("select[name='status']").val('');
        form.render();
        fox_table.reload({});
        return false;
      });
    })
  }
</script>

